package com.yueka.controller;

import com.yueka.pojo.Result;
import com.yueka.pojo.activity.Activity;
import com.yueka.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/activity")
@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping("/list")
    public Result list(String activityName, String status, String isBanner, Integer page, Integer pageSize) {
        try {
            return Result.success(activityService.list(activityName, status, isBanner, page, pageSize));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        try {
            activityService.delete(id);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody Activity activity) {
        try {
            activityService.insert(activity);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody Activity activity) {
        try {
            activityService.update(activity);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

}
